//后台管理部分电影的业务逻辑接口

function saveMovie(movie) {
    const promise = new Promise((resolve, reject) => {
        $.ajax({
            url: baseUrl + 'movie/',
            type: 'POST',
            beforeSend: function (xhr) {
                //请求头部，添加会员卡的名字和会员卡的卡号。
                xhr.setRequestHeader('satoken', tokenValue);
            },
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify(movie), //json对象转换为字符串。
            success: resp => {
                resolve(resp);
            },
            error: err => {
                reject(err);
            }
        })
    })
    return promise;
}

function updateMovie(movie) {
    const promise = new Promise((resolve, reject) => {
        $.ajax({
            url: baseUrl + 'movie/',
            type: 'PUT',
            beforeSend: function (xhr) {
                //请求头部，添加会员卡的名字和会员卡的卡号。
                xhr.setRequestHeader('satoken', tokenValue);
            },
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify(movie), //json对象转换为字符串。
            success: resp => {
                resolve(resp);
            },
            error: err => {
                reject(err);
            }
        })
    })
    return promise;
}


function queryMoviePagerByType(type, keyword, currentPageNumber) {
    const promise = new Promise((resolve, reject) => {
        $.ajax({
            url: baseUrl + 'movie/catalog/pager/' + type + '?keyword=' + keyword + '&currentPageNumber=' + currentPageNumber,
            type: 'GET',
            dataType: 'json',
            success: resp => {
                resolve(resp);

            },
            error: err => {
                reject(err);
            }
        })
    })
    return promise;
}

function queryMovieById(id) {
    const promise = new Promise((resolve, reject) => {
        $.ajax({
            url: baseUrl + 'movie/query/' + id,
            type: 'GET',
            dataType: 'json',
            success: resp => {
                resolve(resp);

            },
            error: err => {
                reject(err);
            }
        })
    })
    return promise;
}